package com.example.blog.mapper;

import com.example.blog.model.BlogInfo;
import com.example.blog.model.PageRequest;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
//blog
//------------+--------------+------+-----+-------------------+----------------+
//        | id          | int(11)      | NO   | PRI | NULL              | auto_increment |
//        | title       | varchar(200) | YES  |     | NULL              |                |
//        | content     | text         | YES  |     | NULL              |                |
//        | user_id     | int(11)      | YES  |     | NULL              |                |
//        | delete_flag | tinyint(4)   | YES  |     | 0                 |                |
//        | create_time | datetime     | YES  |     | CURRENT_TIMESTAMP |                |
//        | update_time | datetime
import java.util.List;
@Mapper
public interface BlogInfoMapper {
    //传递delete_flag是为了我们后面去处理这个值，1为有，0为null这种
    //翻页查询，固定一到五条 offset-进行计算
    @Select("select * from blog where delete_flag=0 order by create_time desc limit #{offset},#{pageSize} ")
    List<BlogInfo> queryBlogListByPage(PageRequest pageRequest);
    //获取总记录数字
    @Select("select count(1) from blog where delete_flag=0 ")
    Integer count();
    //仔细思考一下，这里的创建时间，更新时间，是否需要给用户展示
    @Insert("insert into blog (title,content,user_id) values (#{title},#{content},#{userid})")
    Integer insertBlog(BlogInfo blog);
    @Select("select * from blog where id =#{id} and delete_flag=0")
    BlogInfo queryBlogById(Integer id);
    //使用xml练练手
    Integer DeleteBlogById(Integer id);
    Integer updateBlogById(BlogInfo blog);

}
